package com.ru.application.creditsource.model;

import java.util.List;  
import javax.faces.model.ListDataModel;  
import com.ru.application.creditscore.domain.Car;  
import org.primefaces.model.SelectableDataModel;  
  
public class CarDataModel extends ListDataModel<Car> implements SelectableDataModel<Car> {    
  
    public CarDataModel() {  
    }  
  
    public CarDataModel(List<Car> data) {  
        super(data);  
    }  
      
    @Override  
    public Car getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
        @SuppressWarnings("unchecked")
	List<Car> cars = (List<Car>) getWrappedData();  
        for(Car car : cars) {  
            if(car.getName().equals(new Integer(rowKey)))  
                return car;  
        } 
        return null;  
    }  
  
    @Override  
    public Object getRowKey(Car car) {  
        return car.getName();  
    }  
}  
